<template>
	<view class="">
		<main>
			<view class="flex">
				<view class="pad">
					<view class="img1">
						<img src="../../static/images/score5.png" alt="" srcset="">
					</view>
					<view class="txt1">
						<input type="text" placeholder="请输入支付宝账号" placeholder-class="phcolor"
							v-model="withdrawalInfo.payAccount">
					</view>
				</view>
				<view class="call" @click="submit(1)">
					提交
				</view>
			</view>
		</main>
	</view>
</template>

<script>
	import request from '../../utils/request.js'
	export default {
		data() {
			return {
				aliName: '',
				wxName: '',
				aliAccountNumber: '',
				wxAccountNumber: '',
				num: 0,
				withdrawalInfo: {
					withdrawType: '',
					payAccount: '',
					state:true
				}
			}
		},
	
		methods: {
	        submit(type){
				let that = this
				// 校验支付宝账号是否正确 企业账号只能是邮箱,个人账号可以是邮箱和手机号
				var checkAliAccountNumber = /^(?:1[3-9]\d{9}|[a-zA-Z\d._-]*\@[a-zA-Z\d.-]{1,10}\.[a-zA-Z\d]{1,20})$/
				
				// if (this.withdrawalInfo.aliName == '') {
				// 	uni.showToast({
				// 		title: '支付宝姓名不能为空',
				// 		duration: 2000,
				// 		icon: 'none'
				// 	});
				// } else 
				console.log(this.withdrawalInfo.payAccount)
				if (this.withdrawalInfo.payAccount == '') {
					uni.showToast({
						title: '支付宝账号不能为空',
						duration: 2000,
						icon: 'none'
					});
				} else if (checkAliAccountNumber.test(this.withdrawalInfo.payAccount) == false) {
					uni.showToast({
						title: '支付宝账号格式不正确',
						duration: 2000,
						icon: 'none'
					});
				} else {
					uni.showModal({
						content: '你确定要添加支付宝账号吗？',
						success: function(res) {
							console.log('success', that.withdrawalInfo);
							
							if (res.confirm) {
								request.post('/api/user/withdraw/add',
									that.withdrawalInfo
								).then(res => {
									if (res.code == 0) {
										uni.showToast({
											title: '添加成功',
											icon: 'none',
											duration: 2000
										})
										uni.setStorageSync('aliAccomunt', that.withdrawalInfo.payAccount);
										setTimeout(()=>{
											uni.navigateTo({
												// 			//保留当前页面，跳转到应用内的某个页面
												url: `/pagesA/integral/withdrawal?withdrawType=${type}`
											})
											// uni.navigateTo({
											// 	// 			//保留当前页面，跳转到应用内的某个页面
											// 	url: `/pagesA/integral/withdrawal?withdrawType=${withdrawType}`
											// })
										},2000)
									} else {
										uni.showToast({
											title: res.message,
											icon: 'none',
											duration: 2000
										})
									}
								})
							} else if (res.cancel) {
					
							}
						}
					});
					
					
				}
				
			}
			
	
			
		},
		onLoad(option) {
			
			this.withdrawalInfo.withdrawType = Number(option.Pay)
			console.log(this.withdrawalInfo.withdrawType,'111111111111111111')
		},
		onShow() {
			
			
		}
	}
</script>

<style lang="scss" scoped>
	main {
		// margin: 24rpx;
		padding: 24rpx;
		// margin-top: 131rpx;
		background-color: #FFFFFF;
		// height: 100vh;
	
		.pad {
			width: 100%;
			height: 91rpx;
			display: flex;
			align-items: center;
			border-bottom: 1rpx solid #EBEBEB;
	
			.img1 {
				img {
					width: 16rpx;
					height: 16rpx;
				}
	
			}
	
			.txt1 {
				line-height: 91rpx;
				margin-left: 31rpx;
				font-family: Source Han Sans SC;
				font-weight: 400;
				font-size: 32rpx;
				color: #000000;
				opacity: 0.85;
	            width: 100%;
				.phcolor {
					font-size: 24rpx;
					font-weight: 400;
					opacity: 0.25;
					color: #000000;
				}
			}
		}
	
	}
	
	.call {
		width: 100%;
		height: 90rpx;
		line-height: 90rpx;
		text-align: center;
		background: #FFA500;
		color: white;
		border-radius: 50rpx;
		margin-top: 24rpx;
	}
</style>